//
//  TabbarMenuBtn.m
//  ChatForHot
//
//  Created by FLY on 2018/10/9.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "TabbarMenuBtn.h"

@implementation TabbarMenuBtn

- (instancetype)init{
    
    self = [super init];
    if (self) {
        
        [self addSubview:self.HOTCHATimgView];
        [self addSubview:self.HOTCHATnameLab];
        
        [self.HOTCHATnameLab mas_updateConstraints:^(MASConstraintMaker *make) {
           
//            make.left.right.equalTo(self);
//            make.bottom.equalTo(self).offset(-5);
            make.bottom.equalTo(self).offset(-(HOTCHATTabMenuHeight-50));
            make.left.right.equalTo(self);
            make.height.mas_equalTo(18);
        }];
        
        [self.HOTCHATimgView mas_updateConstraints:^(MASConstraintMaker *make) {
            
            make.centerX.equalTo(self);
            make.bottom.equalTo(self.HOTCHATnameLab.mas_top).offset(2);
        }];
    }
    return self;
}
- (void)setmenuImgStr:(NSString *)menuImgStr{
   
    _menuImgStr = menuImgStr;
    self.HOTCHATimgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",menuImgStr]];
}
- (void)setMenuNameStr:(NSString *)menuNameStr{
    
    _menuNameStr = menuNameStr;
    self.HOTCHATnameLab.text = menuNameStr;
}
- (void)setSelected:(BOOL)selected{
    
    [super setSelected:selected];
    
    self.HOTCHATnameLab.highlighted = selected;
    if (selected) {
        self.HOTCHATimgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@_hig",self.menuImgStr]];
        self.HOTCHATnameLab.text = _menuNameStr;
    }else{
        self.HOTCHATimgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",self.menuImgStr]];
        self.HOTCHATnameLab.text = _menuNameStr;
    }
}
- (void)setBadgeNum:(NSInteger)badgeNum{
    _badgeNum = badgeNum;
    if (badgeNum == 0) {
        self.HOTCHATbadgeView.hidden = YES;
        self.HOTCHATbadgeLab.hidden = YES;
    }else{
        self.HOTCHATbadgeView.hidden = NO;
        self.HOTCHATbadgeLab.hidden = NO;
        if (badgeNum > 99) {
            self.HOTCHATbadgeLab.text = @"99+";
        }else{
            self.HOTCHATbadgeLab.text = [NSString stringWithFormat:@"%zd",badgeNum];
        }
//        [self addAnimation:self.HOTCHATbadgeView];
    }
}
- (void)HOTCHATshowBadgeView{
//    CGSize size = self.HOTCHATimgView.image.size;
//    if (CGSizeEqualToSize(size, CGSizeZero)) {
        [self addSubview:self.HOTCHATbadgeView];
        [self addSubview:self.HOTCHATbadgeLab];
        
        [self.HOTCHATbadgeView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.HOTCHATimgView).offset(3);
            //            make.left.equalTo(self.mas_centerX).offset(size.width / 2 - 10);
            make.left.equalTo(self.HOTCHATimgView.mas_right).offset(-11);
            make.height.mas_equalTo(15);
            make.right.equalTo(self.HOTCHATbadgeLab).offset(6);
        }];
        [self.HOTCHATbadgeLab mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(self.HOTCHATbadgeView);
            make.left.equalTo(self.HOTCHATbadgeView).offset(6);
        }];
//    }
}
//lazzy
- (UILabel *)HOTCHATnameLab{
    
    if (_HOTCHATnameLab == nil) {
        
        _HOTCHATnameLab = [[UILabel alloc]init];
        _HOTCHATnameLab.font = [UIFont systemFontOfSize:10];
        _HOTCHATnameLab.textColor = HOTCHATrgb(128,128,128);
        _HOTCHATnameLab.highlightedTextColor = HOTCHATMainColor;
        _HOTCHATnameLab.textAlignment = NSTextAlignmentCenter;
    }
    return _HOTCHATnameLab;
}
- (UIImageView *)HOTCHATimgView{
    
    if (_HOTCHATimgView == nil) {
        
        _HOTCHATimgView = [[UIImageView alloc]init];
        _HOTCHATimgView.contentMode = UIViewContentModeBottom;
    }
    return _HOTCHATimgView;
}
- (UIImageView *)HOTCHATbadgeView{
    if (_HOTCHATbadgeView == nil) {
        _HOTCHATbadgeView = [[UIImageView alloc] init];
        _HOTCHATbadgeView.image = [[UIImage imageNamed:@"msg_badge"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 6, 1, 6) resizingMode:(UIImageResizingModeStretch)];
        _HOTCHATbadgeView.hidden = YES;
    }
    return _HOTCHATbadgeView;
}

- (UILabel *)HOTCHATbadgeLab{
    if (_HOTCHATbadgeLab == nil) {
        _HOTCHATbadgeLab = [[UILabel alloc] init];
        _HOTCHATbadgeLab.font = [UIFont systemFontOfSize:10];
        _HOTCHATbadgeLab.textColor = [UIColor whiteColor];
        _HOTCHATbadgeLab.textAlignment = NSTextAlignmentCenter;
        _HOTCHATbadgeLab.hidden = YES;
    }
    return _HOTCHATbadgeLab;
}
@end
